package Duoxiancheng;
//龟兔赛跑
public class Guitusaipao implements Runnable{
    private static String Winer;
    @Override
    public void run() {
        for (int i = 0; i <= 100; i++) {
            boolean flag=gameOver(i);
            if (flag){
                break;
            }
            if (Thread.currentThread().getName().equals("兔子")){
                if (i>80) {
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
            System.out.println(Thread.currentThread().getName()+"跑了"+i+"米");
        }
    }
    private boolean gameOver(int steps){
        if (Winer!=null){
            return true;
        }
        if (steps>=100){
            Winer=Thread.currentThread().getName();
            System.out.println("Winer is"+Winer);
            System.out.println(Winer+"牛逼");
            return true;
        }else {
            return false;
        }
    }

    public static void main(String[] args) {
        Guitusaipao guitusaipao=new Guitusaipao();
        new Thread(guitusaipao,"兔子").start();
        new Thread(guitusaipao,"乌龟").start();
    }
}
